package com.you.swagger.main;

import com.you.swagger.controller.IUserInterface;
import com.you.swagger.controller.ProxyUser;
import com.you.swagger.controller.UserInterfaceImpl;
import com.you.swagger.controller.UserInterfaceImplDump;
import com.you.swagger.entity.UserInfo;
import com.you.swagger.service.IUserService;
import com.you.swagger.util.MyClassLoader;
import org.objectweb.asm.util.ASMifier;

import java.lang.annotation.Annotation;

/**
 * @Description
 * @Author yough
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2021/1/12
 */
public class Main {
    public static void main(String[] args) throws Exception {
//        IUserInterface userInterface = (IUserInterface) new ProxyUser().getProxy();
//        userInterface.getUserInfo(new UserInfo());
        ASMifier.main(new String[]{"com.you.swagger.controller.UserInterfaceImpl"});

        // 使用自定义ClassLoader加载asm动态生成的字节码文件
        MyClassLoader myClassLoader = new MyClassLoader();
        Class<?> clazz = myClassLoader.defineClass("com/you/swagger/controller/UserInterfaceImpl", UserInterfaceImplDump.dump());
        System.out.println(clazz.getClassLoader());
        System.out.println(clazz.getName());
        System.out.println(clazz.getSimpleName());
        Annotation[] annotations = clazz.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation.annotationType().getName());
        }
    }
}
